﻿$(function () {
    $(".date-pick").datepicker({ minDate: 0 });
    displayEndDate();
});


//上传文件格式检查
function checkType() {
    var fileName = document.getElementById("ctl00_ContentMain_fileUpLoad").value;
    //返回String对象中子字符串最后出现的位置.  
    var seat = fileName.lastIndexOf(".");
    //返回位于String对象中指定位置的子字符串并转换为小写.  
    var extension = fileName.substring(seat).toLowerCase();
    var allowed = [".jpg", ".gif", ".png", ".bmp", ".jpeg", ".txt", ".rar", ".zip", ".xls", ".pdf", ".doc", ".ppt"];
    for (var i = 0; i < allowed.length; i++) {
        if (!(allowed[i] != extension)) {
            return true;
        }
    }
    alert("不支持" + extension + "格式");
    return false;
}


function validate() {
    //首次添加任务
    if ($("#ctl00_ContentMain_ddlProject").attr("disabled") != "disabled") {
        if ($("#ctl00_ContentMain_ddlProject").val() == "100")
            $("#errorProject").css("display", "inline");
        else {
            $("#errorProject").css("display", "none");
        }
        if ($("#txtHopeDate").val() == "")
            $("#errorDate").css("display", "inline");
        else {
            $("#errorDate").css("display", "none");
        }
        if ($("#ctl00_ContentMain_txtSubject").val() == "")
            $("#errorSubject").css("display", "inline");
        else {
            $("#errorSubject").css("display", "none");
        }
        if ($("#ctl00_ContentMain_txtContent").val() == "")
            $("#errorContent").css("display", "inline");
        else {
            $("#errorContent").css("display", "none");
        }
        if ($("#ctl00_ContentMain_ddlProject").val() == "100" || $("#txtHopeDate").val() == "" || $("#ctl00_ContentMain_txtSubject").val() == "" || $("#ctl00_ContentMain_txtContent").val() == "") {
            return false;
        }
        else {
            return true;
        }
    }
    else {
        if ($("#ctl00_ContentMain_txtContent").val() == "")
            $("#errorContent").css("display", "inline");
        else {
            $("#errorContent").css("display", "none");
        }

        if ($("#ctl00_ContentMain_txtContent").val() == "") {
            return false;
        }
        else {
            return true;
        }
    }
}


//完成日期显示处理
function displayEndDate() {
    if ($("#ctl00_ContentMain_ddlProject").attr("disabled") == "disabled") {
        var date = $("#ctl00_ContentMain_hdnHopeTime").val();
        $("#txtHopeDate").hide();
        $("#lblHopeDate").show().html(date);
    }
    else {
        $("#txtHopeDate").show();
        $("#lblHopeDate").hide();
    }
}
